package wendyeq.iweb.blog.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.GeoPt;
import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Article implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;
	@Persistent
	private String title;
	@Persistent
	private String alias;
	@Persistent(defaultFetchGroup = "true")
	private Text content;
	@Persistent
	private User author;
	@Persistent
	private GeoPt geoPt;
	@Persistent
	private java.util.Date createdTime;
	@Persistent
	private java.util.Date changedTime;
	@Persistent
	private String category;
	@Persistent
	private Boolean isComment = true;// only true or false
	@Persistent(mappedBy = "article")
	@Element(dependent = "true")
	private List<Comment> comments = new ArrayList<Comment>(0);
	@Persistent()
	private Set<String> tags = new HashSet<String>(); // save tag not id
	@Persistent
	private List<String> visitors = new ArrayList<String>(0);// save visitor id

	public Article() {
	}

	public Article(String title, String alias, String content) {
		super();
		this.title = title;
		this.alias = alias;
		this.content = new Text(content);
		this.createdTime = new java.util.Date();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getContent() {
		return content == null ? null : content.getValue();
	}

	public void setContent(String content) {
		this.content = new Text(content);
	}

	public User getAuthor() {
		return author;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	public GeoPt getGeoPt() {
		return geoPt;
	}

	public void setGeoPt(GeoPt geoPt) {
		this.geoPt = geoPt;
	}

	public java.util.Date getCreatedTime() {
		return createdTime;
	}

	public void setCreatedTime(java.util.Date createdTime) {
		this.createdTime = createdTime;
	}

	public java.util.Date getChangedTime() {
		return changedTime;
	}

	public void setChangedTime(java.util.Date changedTime) {
		this.changedTime = changedTime;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public Boolean getIsComment() {
		return isComment;
	}

	public void setIsComment(Boolean isComment) {
		this.isComment = isComment;
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	public Set<String> getTags() {
		return tags;
	}

	public void setTags(Set<String> tags) {
		this.tags = tags;
	}

	public List<String> getVisitors() {
		return visitors;
	}

	public void setVisitors(List<String> visitors) {
		this.visitors = visitors;
	}
}
